import unittest, requests
from ddt import ddt, file_data, data, unpack
from A3mall_csh.csh1.common import read_excel

filepath = r'A3mall_login.xlsx'
shettname = 'Sheet1'
excel_data = read_excel(filepath, shettname)

@ddt()
class A3mall(unittest.TestCase):

    def setUp(self) -> None:
        print('测试开始')

    def tearDown(self) -> None:
        print('测试结束')

    # 登录
    token = None
    @data(*excel_data.getdata_excel())
    @unpack
    def test_a3mall_01(self,username, password):
        r1 = requests.post(url='http://10.59.9.14:7003/api/public/login',
                           json={"username":username,"password":password})
        print(r1.json())
        if r1.json()['data'] != []:
            A3mall.token = r1.json()['data']['token']

    def test_a3mall_02(self):
        r2 = requests.get(url='http://10.59.9.14:7003/api/search/list?page=1&keywords=%E6%B5%8B%E8%AF%95%E6%9C%BA&type=0&sort=1')
        print(r2.json())



    # 添加购物车
    @file_data('./add.json')
    def test_a3mall_03(self, id, num):
        # sku_id是库存单位标识
        r3 = requests.post(url='http://10.59.9.14:7003/api/cart/add',
                           headers={'auth-token':'Bearer ' + str(A3mall.token)},
                           json={"id":id,"sku_id":"","num":num})
        print(r3.json())








if __name__ == '__main__':
    unittest.main()



